<?php

/**
 * 检测超时订单 并修改状态
 */

class Ordertimeout extends Web_Controller
{
	public function __construct()
	{
		parent::__construct();
	}
	/**
	 * [updateStatus 修改订单状态]
	 * @return [type] [description]
	 */
	public function updateStatus()
	{
		$start_time = $this->input->get('start_time');
		$end_time = $this->input->get('end_time');
		$limit = $this->input->get('limit');

		$this->load->model('Order_model');
		$this->load->model('Orderdetail_model');
		$data = $this->Order_model->getOrderTimeoutByTime($start_time,$end_time,$limit);

		//15分钟内的解锁订单
		$arr = array('is_lock'=>2,'update_time <'=>time()-900);

		$this->Order_model->updateOrderStatus($arr);
		
		if(empty($data)) 
		{
			echo json_encode(array('errcode' => 1));//未查询到超时订单
			return;
		}
		
		$orderid = array();
		foreach ($data as $k => $v) {
			$orderid[] = $v['order_id'];
		}
		//修改订单状态
		$this->Order_model->updateOrderStatusByOrderId($orderid);
		$this->Orderdetail_model->updateOrderDetailStatusByOrderId($orderid);
		echo json_encode(array('errcode' => 0));//更新状态成功
	}
}